Add internal APIs to intern a built string without a copy #1185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For example, currently
duk_concat()
creates a fixed buffer for the final result size and writes all string parts into it. The result is then string converted. This means, in practice, that the final string exists in RAM in both the temporary buffer and the finalduk_hstring
for a brief period.Improve this so that internal call sites can push a
duk_hstring
allocated to a certain size but with uninitialized data. The string would also not be tracked in the string table. The calling code could then write to the string data part e.g. as part ofduk_concat()
. Once the data part is done, the sameduk_hstring
allocation can be finished and be interned into the string table, and then becomes immutable.If an error is thrown, garbage collection must deal with a string that needs to be freed but without existing in the string table. Other issues to deal with:
Tasks: